import type { User } from "@/service/api/types/user";
import type { Response } from "@/service/api/types/request";
import type { MockAdapterInstance } from "../index";

import _ from "lodash";

const generateStaffs = (n: number): User[] => {
    const usernames = ["Alice", "Bob", "Charlie", "David", "Eve"];

    return _.times(n, () => {
        return {
            id: _.uniqueId(),
            account: `acc_${_.random(10000, 99999)}`,
            username: _.sample(usernames) as string,
            password: _.random(10000000, 99999999).toString(),
            frozen: _.random(0, 1) === 0,
            role: "staff",
            createdDate: Date.now(),
        };
    });
};

const staffs = generateStaffs(100);

export default function staffMock(mock: MockAdapterInstance) {
    mock.onPost("/user/admin/get_staff/list").reply((config) => {
        const response: Response<User[]> = {} as Response<User[]>;

        const { page, size } = JSON.parse(config.data);

        const start = (page - 1) * size;
        const end = start + size;

        response.code = 1;
        response.data = staffs.slice(start, end);

        return [200, response];
    });
}
